package com.shreecon.lms.persistancy;

import static com.shreecon.lms.interfaces.IMessageConstant.TECH_ERROR;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import com.shreecon.lms.interfaces.LMSException;
import com.shreecon.lms.interfaces.persistance.ILeaveDAO;
import com.shreecon.lms.persistancy.hbm.LeaveAvailablity;

/**
 * The Class LeaveDAO.
 * 
 * @author Santhosh. Modified on Aug 13, 2011
 */
public class LeaveDAO extends ShreeConsDAO  implements ILeaveDAO{

    
    public List<LeaveAvailablity> findByUserId(Long id) throws LMSException {
	Session session = HibernateAccessUtil.getInstance().getSession();
	List<LeaveAvailablity> leaveAvailablity = null;
	try {
		Criteria empCriteria = session.createCriteria(LeaveAvailablity.class);
		empCriteria.add(Restrictions.eq("employeeDetail.empId", id));
		leaveAvailablity = empCriteria.list();
	} catch (RuntimeException re) {
		throw new LMSException(TECH_ERROR,re);
	} finally{
		HibernateAccessUtil.getInstance().closeSession(session);
	}
	return leaveAvailablity;
}
}
